<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <title>Document</title>
</head>
<body>
  <div id="app">
    {{ $data.username }}
  </div>

  <script>

    const app = new Vue({
      data: {
        username: 'ralph'
      },
      // 创建完成之前
      beforeCreate () {
        console.log('beforeCreate');
        console.log('this>>>', this);
        console.log('data>>>', this.$data);
        console.log('el>>>', this.$el);
        console.log(this.username);
      },
      // 创建完成之后
      created () {
        console.log('created');
        console.log('this>>>', this);
        console.log('data>>>', this.$data);
        console.log('el>>>', this.$el);
        console.log(this.username);
        // this.username = 'ralph'
      },
      // 模板渲染完成之前
      beforeMount () {
        console.log('created');
        console.log('this>>>', this);
        console.log('data>>>', this.$data);
        console.log('el>>>', this.$el);
        // this.$el.innerHTML = '123'
      },
      // 模板渲染完成之后
      mounted () {
        console.log('created');
        console.log('this>>>', this);
        console.log('data>>>', this.$data);
        console.log('el>>>', this.$el);
        // this.$el.innerHTML = '123'
        // this.username = 'ralph'
      },
      // 完成数据更新之前
      beforeUpdate () {
        console.log('beforeUpdate');
      },
      // 完成数据更新之后
      updated () {
        console.log('updated');
      },
      beforeDestroy() {
        console.log('beforeDestroy');
      },
      destroyed() {
        console.log('destroyed');
      },
    })

    // 挂载vue实例
    app.$mount('#app')

    // 卸载vue实例
    app.$destroy()
  </script>
</body>
</html>